<template>
  <!--教师端登录-->
  <div class="teacher-login">
    <div class="content">
      <div class="left">
        <p class="left-title">枫叶云直播教育平台</p>
        <img
          class="login-bg"
          src="../../assets/image/login-left-bg.png"
          alt=""
          srcset=""
        />
      </div>
      <div class="right">
        <p class="title">欢迎使用枫叶云直播</p>
        <p class="desc">教师直播端</p>
        <el-form ref="formRef" :model="ruleForm" :rules="rules">
          <el-form-item label="" prop="username">
            <el-input
              :size="size"
              v-model="ruleForm.username"
              placeholder="直播频道号"
            >
              <template #prefix>
                <img
                  class="input-icon"
                  src="../../assets/image/user.png"
                  alt=""
                  srcset=""
                />
              </template>
            </el-input>
          </el-form-item>

          <el-form-item label="" prop="password">
            <el-input
              type="password"
              :size="size"
              style="margin-top: 10px"
              v-model="ruleForm.password"
              placeholder="频道密码"
              show-password
            >
              <template #prefix>
                <img
                  class="input-icon"
                  src="../../assets/image/pwd.png"
                  alt=""
                  srcset=""
                />
              </template>
            </el-input>
          </el-form-item>

          <el-form-item label="">
            <el-button
              class="login-btn"
              :size="size"
              :loading="loading"
              color="#E1463B"
              @click="handleSubmit"
            >
              <span style="color: #fff">登录</span>
            </el-button>
          </el-form-item>
        </el-form>
      </div>
    </div>
  </div>
</template>

<script setup>
import { reactive, ref } from 'vue'
import { useUserStore } from '@/store/modules/user'
import router from '@/router/index'

const userStore = useUserStore()
const formRef = ref(null)
const size = 'large'
const loading = ref(false)

const ruleForm = reactive({
  username: '082039193',
  password: '892484'
})

const rules = {
  username: {
    required: true,
    message: '请输入直播频道号',
    trigger: 'change'
  },
  password: {
    required: true,
    message: '请输入频道密码',
    trigger: 'change'
  }
}

async function handleSubmit() {
  await formRef.value.validate()
  try {
    loading.value = true
    await userStore.userLogin(ruleForm)
    await userStore.getUserInfo()
    loading.value = false
    router.replace({
      path: '/room'
    })
  } catch (e) {
    loading.value = false
    console.error(e)
  }
}
</script>

<style scoped lang="scss">
.teacher-login {
  display: flex;
  justify-content: center;
  align-items: center;
  width: 100%;
  height: 100%;
  background-color: #fff;
  .content {
    display: flex;
    width: 1100px;
    background: #ffffff;
    box-shadow: 0px 0px 43px 0px rgba(0, 0, 0, 0.06);
    border-radius: 30px;
    overflow: hidden;

    .left {
      height: 100%;
      background: linear-gradient(180deg, #d31515, #e1463b);
      color: #fff;
      width: 50%;
      padding: 0 40px;

      .left-title {
        font-size: 70px;
        text-align: center;
        margin-top: 80px;
        padding: 0 40px;
        margin-bottom: 60px;
      }

      .login-bg {
        width: 100%;
      }
    }

    .right {
      width: 50%;
      padding: 80px 90px 60px;

      .title {
        font-size: 40px;
        text-align: center;
        margin-bottom: 20px;
      }
      .desc {
        font-size: 30px;
        text-align: center;
        margin-bottom: 50px;
      }

      .login-btn {
        width: 100%;
        margin-top: 100px;
      }

      .input-icon {
        width: 20px;
        height: 20px;
      }
    }
  }
}
</style>
